class IndexScene extends Scene {
    private btnNum = 0;

    public constructor() {
        super();
        this.addEventListener(Events.ResourceLoadReady, this.created, this);
        this.init('IndexSceneSkin');
    }

    private created(): void {
        const { stageWidth, stageHeight } = this.stage;
        const bg = new egret.Shape();
        bg.graphics.beginFill(ColorHui, 0.7);
        bg.graphics.drawRect(0, 0, stageWidth, stageHeight);
        bg.graphics.endFill();
        this.addToBack(bg);
        
        this.drawMenuBtn('测试', Dispatcher.showTest);
        this.drawMenuBtn('唐诗', Dispatcher.showPoemList);
        this.drawMenuBtn('找数字', Dispatcher.showFindNum);
        this.drawMenuBtn('对对碰', Dispatcher.showDdp);
        // Dispatcher.showTest();

        // const loadingComp = new LoadingComponent();
        // this.addToMain(loadingComp);
    }

    private drawMenuBtn(label: string, tapListener: Function): void {
        const size = {
            top: 160,
            left: 40,
            right: 40,
            bottom: 80,
            marginTop: 20,
            height: 160
        };
        const mBtn = new eui.Button();
        const { stageWidth } = this.stage;
        mBtn.label = label;
        mBtn.skinName = 'resource/eui_skins/MenuButtonSkin.exml';
        mBtn.x = size.left;
        mBtn.y = size.top + this.btnNum * (size.marginTop + size.height);
        mBtn.width = stageWidth - size.left - size.right;
        mBtn.height = size.height;
        mBtn.touchEnabled = true;
        mBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, tapListener, this);
        this.addToMain(mBtn);
        this.btnNum++;
    }
}
